﻿using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using Domain.Dummies;
using Domain.Dummies.Dtos;
using Domain.Dummies.Dtos.Collections;

namespace Services.Dummies.HrService
{
    public class DummyHrService : IHrService
    {
        #region IHrService Members

        public StudentDto GetStudent(SessionDto session, System.Guid StudentGuid)
        {
            StudentDto studentdto = new StudentDto() 
            {
                Id = Guid.Empty,
                Name = "Такой студент не найден"
            };

            IEnumerable<StudentDto> query = Database.get().Students.Where(student => student.Id.Equals(StudentGuid));
            
            if (query.Count() != 0)            
                studentdto = query.First();                       

            return studentdto;
        }

        public TeacherDto GetTeacher(SessionDto session, System.Guid TeacherGuid)
        {
            TeacherDto teacherdto = new TeacherDto()
            {
                Id = Guid.Empty,
                Name = "Такой преподаватель не найден"
            };

            IEnumerable<TeacherDto> query = Database.get().Teachers.Where(teacher => teacher.Id.Equals(TeacherGuid));
            if (query.Count() != 0)            
                teacherdto = query.First();
            
            return teacherdto;
        }

        public Guid CreateStudent(SessionDto session, StudentDto student)
        {
            student.Id = Guid.NewGuid();
            Database.get().Students.Add(student);
            return student.Id;
        }

        public bool DeleteStudent(SessionDto session, Guid studentId)
        {
            var query = Database.get().Students.Where(student => student.Id.Equals(studentId));
            if (query.Count() != 0)
            {
                Database.get().Students.Remove(query.First());
                return true;
            }
            else
                return false;
        }

        public Guid CreateTeacher(SessionDto session, TeacherDto teacher)
        {
            teacher.Id = Guid.NewGuid();
            Database.get().Teachers.Add(teacher);
            return teacher.Id;
        }

        public bool DeleteTeacher(SessionDto session, Guid teacherId)
        {
            var query = Database.get().Teachers.Where(teacher => teacher.Id.Equals(teacherId));
            if (query.Count() != 0)
            {
                Database.get().Teachers.Remove(query.First());
                return true;
            }
            else
                return false;
        }

        public Guid? GetStudentId(SessionDto session, StudentDto student)
        {
            throw new NotImplementedException();
        }

        public Guid? GetTeacherId(SessionDto session, TeacherDto teacher)
        {
            throw new NotImplementedException();
        }

        public bool UpdateStudent(SessionDto session, Guid studentId, StudentDto student)
        {
            throw new NotImplementedException();
        }

        public bool UpdateTeacher(SessionDto session, Guid teacherId, TeacherDto teacher)
        {
            throw new NotImplementedException();
        }

        public PersonListGuidsDto GetStudents(SessionDto session)
        {
            PersonListGuidsDto guids = new PersonListGuidsDto();
            guids.Guids = Database.get().Students.Select(student => student.Id).ToList();
            return guids;
        }

        public PersonListGuidsDto GetTeachers(SessionDto session)
        {
            PersonListGuidsDto guids = new PersonListGuidsDto();
            guids.Guids = Database.get().Teachers.Select(teacher => teacher.Id).ToList();
            return guids;
        }

        #endregion
    }
}
